<template>
  <el-dialog
    :visible="visible"
    title="新建文件夹"
    width="20%"
  >
    <el-form layout="vertical">
      <el-form-item label="文件夹名称">
        <el-input v-model="fileName" />
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="Onclose">取 消</el-button>
      <el-button type="primary" @click="creator">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  name: 'MyContentAdd',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    parentId: {
      type: String,
      default: '0'
    }
  },
  data() {
    return {
      fileName: '',
      confirmLoading: false
    }
  },
  methods: {
    creator() {
      if (this.fileName === '') return this.$message.warning('文件名不能为空！')
      const newShare = {
        parentId: this.parentId,
        fileName: this.fileName,
        mark: 1
      }
      this.confirmLoading = true
      this.$post('/fileadmin/add', newShare).then(res => {
        // 清空表单
        this.confirmLoading = false
        this.$emit('create')
      })
    },
    Onclose() {
      // 清空表单
      this.fileName = ''
      this.$emit('cancel')
    }
  }
}
</script>

<style scoped>

</style>
